#pragma once
#include<iostream>
using namespace std;
namespace My_list
{
	template<class T>
	struct ListNode
	{
		ListNode<T>* _next;
		ListNode<T>* _prev;
		T _data;

		ListNode(const T& data = T())
			:_data(data)
			,_next(nullptr)
			,_prev(nullptr)
		{

		}
	};
	template<class T>
	class ListIterator
	{
		typedef ListNode<T> Node;
		typedef ListIterator<T> Self;

		Node* _node;
	public:
		ListIterator(Node* node)
			:_node(node)
		{ }
		Self& operator++()
		{
			_node = _node->_next;
			return *this;
		}
		Self operator++(int)
		{
			Self tmp(*this);
			_node = _node->_next;
			return tmp;
		}

		Self& operator--()
		{
			_node = _node->_prev;
			return *this;
		}
		Self operator--(int)
		{
			Self tmp(*this);
				_node  = _node->_prev;
			return tmp;
		}

		T& operator*()
		{
			return _node->_data;
		}
		bool operator!=(const Self& it)
		{
			return  _node != it._node;
		}
	};
	template<class T>
	class list
	{
		typedef ListNode<T> Node;
	public:
		typedef ListIterator<T> iterator;

			iterator begin()
		{
				return iterator(_head->_next);
		}
			iterator end()
			{
				return iterator(_head);
			}
		list()
		{
			_head = new Node(T());
			_head->_next = _head;
			_head->_prev = _head;
		}
		void push_back(const T& x)
		{
			Node* newnode = new Node(x);
			Node* tail = _head->_prev;
			tail->_next = newnode;
			newnode->_prev = tail;
			newnode->_next = _head;
			_head->_prev = newnode;
		}
	private:
		Node* _head;
	};
	void test_list1()
	{
			list<int> lt1;
			lt1.push_back(1);
			lt1.push_back(2);
			lt1.push_back(3);
			list<int>::iterator it = lt1.begin();
			while (it != lt1.end())
			{
				cout << *it << " ";
				++it;
			}

	}


}